package com.vision.controller;

import com.vision.pojo.AjaxResult;
import com.vision.pojo.vo.ChatUserVO;
import com.vision.pojo.vo.MessageVO;
import com.vision.pojo.vo.PageVO;
import com.vision.pojo.vo.SystematicNotificationVO;
import com.vision.service.MessageService;
import org.apache.ibatis.annotations.Delete;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 获取所有系统通知
     * @param pageNum 页码
     * @param pageSize 每页显示的条数
     * @return 所有系统通知
     */
    @GetMapping("/getAllSystematicNotification")
    public AjaxResult<PageVO<SystematicNotificationVO>> getAllSystematicNotification (@NotNull Integer pageNum, @NotNull Integer pageSize) {
        return AjaxResult.success(messageService.getAllSystematicNotification(pageNum,pageSize));
    }

    /**
     * 获取所有同聊天的用户
     * @param pageNum 页码
     * @param pageSize 每页显示的条数
     * @return 所有聊天记录
     */
    @GetMapping("/getAllChatList")
    public AjaxResult<PageVO<ChatUserVO>> getAllChatList (@NotNull Integer pageNum, @NotNull Integer pageSize) {
        return AjaxResult.success(messageService.getAllChatList(pageNum,pageSize));
    }

    /**
     * 获取所有聊天记录
     * @param pageNum 页码
     * @param pageSize 每页显示的条数
     * @param talkingId 目标对象聊天 id
     * @return 所有聊天记录
     */
    @GetMapping("/getAllChatHistory")
    public AjaxResult<PageVO<MessageVO>> getAllChatHistory (@NotNull Integer pageNum, @NotNull Integer pageSize, @NotNull Integer talkingId) {
        return AjaxResult.success(messageService.getAllChatHistory(pageNum,pageSize,talkingId));
    }

    /**
     * 删除聊天记录
     * @param talkingId 目标对象聊天 id
     * @return 删除聊天记录
     */
    @DeleteMapping("/removeHistory")
    public AjaxResult removeHistory (@NotNull Integer talkingId) {
        messageService.removeHistory(talkingId);
        return AjaxResult.success();
    }
}
